package com.visitor.registration.task;

import com.visitor.registration.service.VisitorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 邮件定时发送任务
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class EmailScheduleTask {

    private final VisitorService visitorService;

    /**
     * 每天晚上20:00自动发送Excel表格到邮箱
     * cron表达式：秒 分 时 日 月 周
     */
    @Scheduled(cron = "0 0 20 * * ?")
    public void sendDailyReport() {
        log.info("开始执行每日访客报表发送任务...");
        try {
            visitorService.generateReportAndSendMail();
            log.info("每日访客报表发送成功");
        } catch (Exception e) {
            log.error("每日访客报表发送失败", e);
        }
    }
} 